package com.weirong.smartvault.backservice.util.table;

import com.google.gson.annotations.Expose;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kfeb4
 * Date: 2017/12/29
 * Time: 17:04
 */
public class Tree <T>{
    @Expose List<Tree<T>> sons = new ArrayList<>();
    @Expose(serialize = false,deserialize = false) T obj;
    @Expose public String additionInf;


    public Tree(T obj){
        this.obj = obj;
    }

    public Object getObj() {
        return obj;
    }

    public void addSon(Tree node){
        sons.add(node);
    }
    public Integer width(){
        Integer width=0;
        for(Tree node:sons){
            width+=node.width();
        }
        return width==0?1:width;
    }
    public List<Tree<T>> getEndPoints(){
        List<Tree<T>> res = new ArrayList<>();
        for(Tree<T> t :sons){
            res.addAll(t.getEndPoints());
        }
        if(res.size()==0)
            res.add(this);
        return res;
    }
}
